#ifndef WebSocketService_WSProtocol_MySqlDb_H
#define WebSocketService_WSProtocol_MySqlDb_H

#include <oxf.h>
#include "AbstractDb.h"
#include "SqlDb.h"

#ifdef _WIN32

#include <mysql.h>

#else
#include <mysql/mysql.h>
#endif

class MySqlDb : public SqlDb {
public :

    mutable MYSQL_RES *_result[MaxTable];

    MySqlDb(const resip::Data &host, const resip::Data &user, const resip::Data &password,
            const resip::Data &databaseName, unsigned int port);

    virtual ~MySqlDb();

    resip::Data dbNextKey(const Table table, bool first);

    //## operation initialize() const
    void initialize() const;

    int connectToDatabase() const;

    void setMySqlMode() const;

    void disconnectFromDatabase() const;

    int query(const resip::Data &queryCommand, MYSQL_RES **result) const;

    int query(const resip::Data &queryCommand) const;

    virtual int AddPlateInfo(std::string &plateName, std::string &plateType, float confidence, std::string &fPath,
                     std::string &pPath, std::string &time);

    void QueryPlateInfoListSum(const std::string &startTime, const std::string &endTime, int &sum);

    void QueryPlateInfoList(int startNum, int endNum, const std::string &startTime, const std::string &endTime,
                            std::vector<PlateInfoRecord> &plateInfoRecordList);

    mutable MYSQL *_conn;

    resip::Data _dbHost;

    resip::Data _dbName;

    resip::Data _dbPassword;

    unsigned int _dbPort;

    resip::Data _dbUser;

};

#endif
